
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;
using HousingInfo.DataLinQ;

namespace HousingInfo.Library
{ 
	public partial class NewsSaveBO : Csla.BusinessBase<NewsSaveBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in NewsSaveBO
			//AuthorizationRules.AllowRead(NewsSaveIDProperty, "NewsSaveBOReadGroup");
			//AuthorizationRules.AllowRead(NewsHouseIDProperty, "NewsSaveBOReadGroup");
			//AuthorizationRules.AllowRead(UserNameProperty, "NewsSaveBOReadGroup");

			//AuthorizationRules.AllowWrite(NewsHouseIDProperty, "NewsSaveBOWriteGroup");
			//AuthorizationRules.AllowWrite(UserNameProperty, "NewsSaveBOWriteGroup");
		}

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of NewsSaveBO
			//AuthorizationRules.AllowCreate(typeof(NewsSaveBO), "NewsSaveBOCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(NewsSaveBO), "NewsSaveBOEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(NewsSaveBO), "NewsSaveBODeleteGroup"));
		}
		#endregion //Authorization Rules
		private void AssignParentKey(HousingInfo.DataLinQ.NewsSave data)
		{
            //data.ParentId = ReadProperty<ParentBO>(ParentBOProperty).Id;
		}

        #region Lay Id cua newssave theo id newshouse va user name
        public static int LayIdNewsSave_ByNewsHouseAndUserName(int newshouseid, string username)
        {
            int count = 0;
            using (var mgr = ContextManager<HousingInfoDataContext>
                    .GetManager(Database.HousingInfoConnection))
            {
                try
                {
                    var result = from row in mgr.DataContext.NewsSaves
                                 where row.UserName == username && row.NewsHouseID == newshouseid
                                 select row;
                    foreach (var detail in result)
                    {
                        count = detail.NewsSaveID;
                        break;
                    }
                }
                catch { }
            }

            return count;
        }
        #endregion

	}
}
